package com.codingbros.header 
{
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import com.codingbros.header.graphics.GraphicsWobblyLines;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.TextField;

	
	public class Header extends Sprite 
	{	
		private static const WIDTH:int = 1000;
		private static const HEIGHT:int = 240;		
				
		private var _headerGraphics:GraphicsWobblyLines;
		
		private var _headerButton:Sprite;
		
		private var _name:String;
		private var _url:String;
		private var _urlRequest:URLRequest;
		
		public function Header () 
		{
			_headerGraphics = new GraphicsWobblyLines();
			this.addChild(_headerGraphics);
			
			_headerButton = new Sprite();
			this.addChild(_headerButton);
			
			if (stage.loaderInfo.parameters.name) {
				_name = stage.loaderInfo.parameters.name;
			} else {
				_name = "damn fool no name param";
			}
			
			
			if (stage.loaderInfo.parameters.url) {
				_url = stage.loaderInfo.parameters.url;
				_urlRequest = new URLRequest(_url);
				TextField(_headerText).addEventListener(MouseEvent.MOUSE_UP, onUp);
			} else {
				_name = "damn fool no url param";
			}
			
			TextField(_headerText).text = _name;
			
			TextField(_headerText).selectable = false;
			
			TextField(_headerText).addEventListener(MouseEvent.MOUSE_OVER, onOver)
			TextField(_headerText).addEventListener(MouseEvent.MOUSE_OUT, onOut);
		}
		
		private function onOver(e:MouseEvent):void 
		{
			TextField(_headerText).textColor = 0x3E8F66;
		}
		
		private function onOut(e:MouseEvent):void 
		{
			TextField(_headerText).textColor = 0;
		}
		
		private function onUp(e:MouseEvent):void 
		{
			navigateToURL(_urlRequest, "_self");
		}
	}
}
